package com.hspedu.newData.dmsxl.哈希表;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-04-29 
 * @Version: 1.0
 */

public class LC128最长连续序列 {

    public int longestConsecutive(int[] nums) {
        Set<Integer> set = new HashSet<>();

        for (int i = 0; i < nums.length; i++) {
            set.add(nums[i]);
        }

        int count = 0;
        for (Integer i : set) {
            if (!set.contains(i-1)){
                int current = i;
                int currentCount = 1;
                while(set.contains(current+ 1)){
                    current ++;
                    currentCount ++;
                }

                count = Math.max(count ,currentCount);
            }
        }
        return count;
    }
}
